import "package:flutter/material.dart";

/// 按钮菜单项
class ButtonMenuItem {
  final String label; //按钮名称
  final String value; //按钮值
  ButtonMenuItem({
    required this.label,
    required this.value,
  });
}

/// 影视按钮类型菜单
class MovieButtonMenu extends StatefulWidget {
  final List<ButtonMenuItem> items;
  final Function(String) onTap;
  final String activeValue; //激活值
  const MovieButtonMenu({
    super.key,
    required this.items,
    required this.onTap,
    required this.activeValue,
  });

  @override
  State<MovieButtonMenu> createState() => _MovieButtonMenuState();
}

TextStyle activeTextStyle = const TextStyle(
  fontSize: 13,
  color: Color(0xff1c1c1c),
  fontWeight: FontWeight.bold,
);
TextStyle inactiveTextStyle = const TextStyle(
  fontSize: 13,
  color: Color(0xff6d757a),
);

class _MovieButtonMenuState extends State<MovieButtonMenu> {
  @override
  Widget build(BuildContext context) {
    return Container(
      height: 28,
      color: Colors.white,
      child: ListView.builder(
        scrollDirection: Axis.horizontal,
        itemCount: widget.items.length,
        itemBuilder: (context, index) {
          ButtonMenuItem item = widget.items[index];
          bool isActive = item.value == widget.activeValue;
          return GestureDetector(
            onTap: () {
              widget.onTap(item.value);
            },
            child: Container(
              padding: const EdgeInsets.symmetric(horizontal: 14),
              margin: EdgeInsets.only(
                left: index == 0 ? 12 : 0,
                right: index == widget.items.length - 1 ? 12 : 0,
              ),
              decoration: BoxDecoration(
                color: isActive ? const Color(0xfff1f2f3) : Colors.transparent,
                borderRadius: BorderRadius.circular(16),
              ),
              alignment: Alignment.center,
              child: Text(
                item.label,
                style: isActive ? activeTextStyle : inactiveTextStyle,
              ),
            ),
          );
        },
      ),
    );
  }
}
